package com.jianganming.singleton;

import java.util.Objects;

/**
 * 双重检测锁
 * 特点：安全且在多线程情况下能保持高性能
 */
public class Singleton3 {
    private static Singleton3 singleton;
    public static Singleton3 getInstance(){
        if(Objects.isNull(singleton)){
            synchronized (Singleton3.class){
                if(Objects.isNull(singleton)){
                    singleton = new Singleton3();
                }
            }
        }
        return singleton;
    }

    public static void main(String[] args) {
        Singleton3 instance = Singleton3.getInstance();
        Singleton3 instance1 = Singleton3.getInstance();
        System.out.println(instance==instance1);
    }
}
